package com.yitianyigexiangfa;

import java.io.*;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;

/**
 * Created by liubei on 2017/3/16.
 */
public class Hammer005 {

    public static void main(String[] args) throws IOException {
        while(true){
            // 创建socket客户端
            Socket client = new Socket("192.168.31.151", 4667);
            // 创建IO
            DataInputStream input = new DataInputStream(client.getInputStream());
            // 创建输出流
            DataOutputStream output = new DataOutputStream(client.getOutputStream());
            // 输出提示
            System.out.print("请输入：");
            // 从控制台获取输入
            String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
            // 输出
            output.writeUTF(s);
            char[] chars = s.toCharArray();
            // 遍历数组
            for (char c: chars){
                System.out.print("-----");
                System.out.print(c);
                output.writeByte((byte)c);
            }
             // 获取收到的数据
            String result = input.readUTF();
            // 打印收到的数据
            System.out.print(result);
        }
    }
}
